import { getUrlTabId, getTabIdForWinAllUrlTab } from '../utils/tools'

// let resprnsDataList = []
// let refoNum = 5
// const requestContent = (data, tabid) => {
//     console.log('data===》〉》〉', data)

//     // return new Promise(async (resolve, reject) => {
//     //     // resprnsDataList.push({ data, resolves: resolve, refoNum, useNum: 0 })
//     //     getUrlTabId('https://fxg.jinritemai.com').then(itecon => {
//     //         // console.log('itecon666', itecon)
//     //         const currentTab = itecon.id
//     //         chrome.tabs.sendMessage(currentTab, { method: 'dly-bgs', type: 'originHttpWin', data }, function (response) {
//     //             // console.log('请求结果 发现过期该如何应对 选择刷新脚本与页面 重置所有内容， 并修改进行中的为未开始并通知到所有的页面 还需要发送短信给用户', response)
//     //             // console.log('****', response)
//     //             // if(response.code) {

//     //             //     resprnsDataList.forEach(reit => {
//     //             //         reit.resolves(response)
//     //             //     })
//     //             //     resprnsDataList = []
//     //             // }
//     //             resolve(response)
//     //         });
//     //     })
//     // })
// }
const requestContent = (data, tabid) => {

    return new Promise(async (resolve, reject) => {
        // resprnsDataList.push({ data, resolves: resolve, refoNum, useNum: 0 })
        getUrlTabId('https://fxg.jinritemai.com').then(itecon => {
            // console.log('itecon666', itecon)
            const currentTab = itecon.id
            chrome.tabs.sendMessage(currentTab, { method: 'dly-bgs', type: 'originHttpWin', data }, function (response) {
                // console.log('请求结果 发现过期该如何应对 选择刷新脚本与页面 重置所有内容， 并修改进行中的为未开始并通知到所有的页面 还需要发送短信给用户', response)
                // console.log('****', response)
                // if(response.code) {

                //     resprnsDataList.forEach(reit => {
                //         reit.resolves(response)
                //     })
                //     resprnsDataList = []
                // }
                resolve(response)
            });
        })
    })
}

export const requerconetnt = (data, type, tabid) => {
    if (!type) return
    return new Promise(async (resolve, reject) => {
        getUrlTabId('https://fxg.jinritemai.com').then(itecon => {
            console.log('iteconitecon', itecon)
            const currentTab = itecon.id
            chrome.tabs.sendMessage(currentTab, { method: 'dly-bgs', type: type, data }, function (response) {
                resolve(response)
            });
        })
    })
}

export const requerconetntAll = (data, type, tabid) => {
    if (!type) return
    // console.log('requerconetntAll', data, type, tabid)

    return new Promise(async (resolve, reject) => {
        if (tabid) {
            chrome.tabs.sendMessage(tabid, { method: 'dly-bgs', type: type, data }, function (response) {
                resolve(response)
            });
        }
        getTabIdForWinAllUrlTab('https://fxg.jinritemai.com').then(itecon => {
            itecon.forEach(reit => {
                const currentTab = reit.id
                chrome.tabs.sendMessage(currentTab, { method: 'dly-bgs', type: type, data }, function (response) {
                    resolve(response)
                })
            })
        })
    })
}

export default requestContent
